package com.lhyl.front.common;

import java.util.Iterator;
import java.util.List;

import com.lhyl.front.exception.LotteryBetsException;
import com.lhyl.front.web.lottery.model.LotteryBets;
import com.lhyl.front.web.shiro.model.User;

/***
 *  用户投注的校验
 * @author huang
 *
 */
public class LotteryBetsVerification {
 
	  /***
	   * 
	   * @param lotteryBets 当前的投彩记录
	   * @param vo 当前登录用户
	   * @throws LotteryBetsException
	   */
	  public static void verificationBets(List<LotteryBets>lotteryBets,User vo)throws LotteryBetsException
	  {
		    double sumBets =sumBetsAmount(lotteryBets);// 获取所有投注的总金额
		    if(vo.getCoin()<sumBets)
		    {
				throw LotteryBetsException.makeCreditLowEx();
			}
	  }
	  
	  /***
	   * 
	   * @throws LotteryBetsException
	   */
	  public static double sumBetsAmount(List<LotteryBets>lotteryBets) 
	  {
		   Iterator<LotteryBets>iter = lotteryBets.iterator();
		   LotteryBets bets = null;
		   double sumBets = 0d;
		   while(iter.hasNext())
		   {
			   bets = iter.next();
			   sumBets+=bets.getBetsAmount();
		   }
		   return sumBets;
		  
	  }
}
